<?php

/*
 * File block.accesscount.php for project Rijlesplanner.nl
 * Created on 28 nov 2007 at 22:38:24 by Ivar Pruijn
 */

/**
 * Determines whether the current user has a count higher than zero for the level in the module specified in the 'module' parameter
 * @tutorial http://smarty.php.net/manual/en/plugins.block.functions.php Smarty Tutorial
 * @param array $params The parameters passed to this function from the Smarty template
 * @param string $content The content between the function blocks
 * @param Smarty $smarty The Smarty template
 * @param boolean $repeat TRUE at the first call of the block-function (the opening tag) and FALSE on all subsequent calls to the block function (the block's closing tag)
 */
function smarty_block_accesscount($params, $content, & $smarty, & $repeat) {
	global $logger;
	if (!isset ($params['module']) || empty ($params['module'])) {
		$logger->log("Access plugin: missing parameter 'module'", PEAR_LOG_WARN);
		// $smarty->trigger_error("access plugin: missing parameter 'module'");
		return;
	} else if (!isset ($params['level1']) || empty ($params['level1'])) {
		$logger->log("Access plugin: missing parameter 'level1'", PEAR_LOG_WARN);
		// $smarty->trigger_error("access plugin: missing parameter 'level1'");
		return;
	} else {
		$module = $params['module'];
		$level1 = $params['level1'];
		$user = $_SESSION['user'];
		$acl = $user->getACL($module);
		if (count($acl['$module']['$level1']) <= 0) {
//			$logger->log("Level " . $level1 . " for module " . $module . " count is zero", PEAR_LOG_DEBUG);
			return;
		}
	}
	return $content;
}
?>
